<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        function fun(str) {
            //  遍历形参str，循环一半
            for (var i = 0; i <= str.length / 2; i++) {
                //  假如第i个值和倒是第i的值相等，则返回true
                if (str[i] === str[str.length - 1]) {
                    return true
                    //  反之返回 false
                } else {
                    return false
                }
            }
        }
        var res = prompt('请输入内容')
        alert('可回文字符串→ ' + fun(res))
    </script>
</body>

</html>